// pages/myself/trorder.js
var util = require('../../utils/util.js');
const app = getApp()
Page({
    data: {
      listInfo: [],
      showModalStatus: false,
      animationData: '',
      orderList: []
    },
    onItemClick: function (e) {
        var index = e.currentTarget.dataset.itemIndex;
    },
    onLoad: function () {
      if (!app.globalData.isLoginAuth) {
        this.showModal();
      }
    },
    onShow: function (options) {
      if (app.globalData.isLoginAuth) {
        this.setData({
          listInfo: app.globalData.listInfo
        })
        this.getOrderlist()
      }
    },
    getOrderlist:function(){
        var that=this;
        wx.request({
            url: app.globalData.hostUrl + 'member/trorderlist',
            data: {
                uid: wx.getStorageSync('userId'),
            },
            method: 'GET',
            success: function (res) {
                console.log(res);
                that.setData({
                    orderList: res.data.result
                })
            },
            fail: function (res) {
                console.log(res.data);
                console.log('is failed')
            }
        })
    },
    goorderdetail:function(e){
        var rid = e.currentTarget.dataset.rid;
        var cf = e.currentTarget.dataset.cf;
        if(cf=='xc'){
            var gotourl ='../xuecar/orderdetail?oid='+rid;
        }
        else if(cf == 'pl'){
            var gotourl = '../traincar/orderdetail?oid=' + rid;
        }
        else if (cf == 'kp') {
            var gotourl = '../keepcar/orderdetail?oid=' + rid;
        }
        wx.navigateTo({
            url: gotourl
        })
    },
  modifyfinish: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.oid;
    var cf = e.currentTarget.dataset.cf;
    var finish = 3;
    var tipstr = '请确认销售员是否已提供购车服务?';
   
    wx.showModal({
      content: tipstr,
      showCancel: true,
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.hostUrl + 'member/modifyfinish',
            data: {
              flag: cf,
              fval: finish,
              id: id
            },
            methods: 'GET',
            success: function (res) {
              console.log(res);
              if (res.data.code == 200) {
                that.setData({
                  isshow: true
                })
                wx.navigateTo({
                  url: '../myself/trorder',
                })
              }
              else {
                wx.showToast({
                  title: '操作失败',
                  icon: 'error',
                  duration: 2000
                })
              }
            }
          })
        }
      }
    });
  },
  gohome: function () {
    wx.redirectTo({
      url: '../index/index',
    })
  },
  yuy: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../myself/thappointment',
      })
    }
    else {
      wx.redirectTo({
        url: '../myself/myappointment',
      })
    }
  },
  orders: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../myself/trorder',
      })
    }
    else {
      wx.redirectTo({
        url: '../myself/myorder',
      })
    }
  },
  mys: function () {
    wx.redirectTo({
      url: '../myself/myself',
    })
  },
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "ease-in-out",
      delay: 0
    })
    this.animation = animation
    animation.translateY(500).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  hideModal: function () {
    this.setData({
      showModalStatus: false,
    })
  },
  bindGetUserInfo: function (e) {
    console.log(e);
    if (e.detail.errMsg == 'getUserInfo:ok') {
      app.globalData.userInfo = e.detail.userInfo;
      app.getfansinfo();
    }
    else {
      wx.redirectTo({
        url: '../index/index',
      })
    }
  }
})